/**
 * 
 */
package com.cua24.donkeyroll;

import org.andengine.engine.camera.Camera;
import org.andengine.entity.scene.menu.MenuScene;
import org.andengine.entity.scene.menu.MenuScene.IOnMenuItemClickListener;
import org.andengine.entity.scene.menu.item.IMenuItem;
import org.andengine.entity.scene.menu.item.SpriteMenuItem;
import org.andengine.entity.scene.menu.item.decorator.ScaleMenuItemDecorator;
import org.andengine.entity.sprite.Sprite;
import org.andengine.opengl.util.GLState;

import com.cua24.donkeyroll.SceneManager.SceneType;

/**
 * @author dikaberg
 *
 */
public class MainMenuScene extends BaseScene implements IOnMenuItemClickListener {

	/* (non-Javadoc)
	 * @see com.cua24.donkeyroll.BaseScene#createScene()
	 */
	@Override
	public void createScene() {
		createBackground();
		createMenuChildScene();
	}

	/* (non-Javadoc)
	 * @see com.cua24.donkeyroll.BaseScene#onBackKeyPressed()
	 */
	@Override
	public void onBackKeyPressed() {
		System.exit(0);
	}

	/* (non-Javadoc)
	 * @see com.cua24.donkeyroll.BaseScene#disposeScene()
	 */
	@Override
	public void disposeScene() {
		// TODO Auto-generated method stub

	}

	@Override
	public SceneType getSceneType() {
		return SceneType.SCENE_MENU;
	}
	
	private void createBackground(){
		attachChild(new Sprite(400,200,resourcesManager.menu_background_region,vbom){
			@Override
			protected void preDraw(GLState pGLState,Camera camera){
				super.preDraw(pGLState, camera);
				pGLState.enableDither();
			}
		});
	}
	private MenuScene menuChildScene;
	private final int MENU_PLAY = 0;
	private final int MENU_OPTIONS = 1;
	
	private void createMenuChildScene(){
		menuChildScene = new MenuScene(camera);
		menuChildScene.setPosition(400,240);
		final IMenuItem playMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_PLAY,resourcesManager.play_region,vbom),1.2f,1);
		final IMenuItem optionsMenuItem = new ScaleMenuItemDecorator(new SpriteMenuItem(MENU_OPTIONS,resourcesManager.options_region,vbom),1.2f,1);
		menuChildScene.addMenuItem(playMenuItem);
		menuChildScene.addMenuItem(optionsMenuItem);
		menuChildScene.buildAnimations();
		menuChildScene.setBackgroundEnabled(false);
		playMenuItem.setPosition(0,0);
		optionsMenuItem.setPosition(0,-100);
		menuChildScene.setOnMenuItemClickListener(this);
		setChildScene(menuChildScene);
	}

	@Override
	public boolean onMenuItemClicked(MenuScene pMenuScene, IMenuItem pMenuItem,
			float pMenuItemLocalX, float pMenuItemLocalY) {
		switch(pMenuItem.getID()){
		case MENU_PLAY:
			SceneManager.getInstance().loadGameScene(engine);
			return true;
		case MENU_OPTIONS:
			return true;
		default:
			return false;
		}
	}
	
}
